package cn.schoolwow.quickdao.test.module.business.user.dql.general.flow;

import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickdao.domain.database.dql.condition.Condition;
import cn.schoolwow.quickdao.test.entity.User;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import org.junit.Assert;

public class ConditionCloneFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        DAO dao = flowContext.checkInstanceData(DAO.class);

        Condition condition = dao.query(User.class)
                .addQuery("password", "123456")
                .addColumn("username");
        for(int i=0;i<10;i++){
            String username = "user"+i;
            Condition cloneCondition1 = condition.clone().addQuery("username", username);
            String actualUsername = (String) cloneCondition1
                    .execute()
                    .getSingleColumn(String.class);
            Assert.assertEquals(username, actualUsername);
        }
    }

    @Override
    public String name() {
        return "用户查询Condition对象的clone方法测试";
    }
}
